package com.sinog.auth.util;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * @desc 封装post工具类
 * @author lk
 * @date 2020-05-29 18:32:30
 */
public class HttpUtils {

    /**
     * 后台进行POST请求
     * @param response response
     * @param postUrl postUrl
     * @param paramMap paramMap
     */
    public static void doBgPostReq(HttpServletResponse response, String postUrl, Map<String, ?> paramMap) throws IOException {
        response.setContentType( "text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("<form name='postSubmit' method='post' action='"+postUrl+"' >");
        for (String key : paramMap.keySet()) {
            out.println("<input type='hidden' name='"+key+"' value='" + paramMap.get(key)+ "'>");
        }
        out.println("</form>");
        out.println("<script>");
        out.println("document.postSubmit.submit()");
        out.println("</script>");
    }
}